﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using devtm.Aop.Event;
using System.Linq.Expressions;

namespace devtm.Aop.Linq.Boxs
{
    
    
    internal class InterceptorDelegateBox : InterceptorBase
    {


        public InterceptorDelegateBox(InterceptEnumEventType typeEvent, Action<object, InterceptEventArgs, int> e)
        {

            SetMethods(typeEvent, e);
          
        }

        public void SetMethods(InterceptEnumEventType typeEvent, Action<object, InterceptEventArgs, int> e)
        {

            switch (typeEvent)
            {
                case InterceptEnumEventType.BeforeCall:
                    if (BeforeMethod == null)
                        BeforeMethod = e.Method;
                    else
                        throw new Exception("type event " + typeEvent.ToString() + " allreader setted.");
                    
                    break;
                case InterceptEnumEventType.InterceptCall:
                    if (InterceptMethod == null)
                        InterceptMethod = e.Method;
                    else
                        throw new Exception("type event " + typeEvent.ToString() + " allreader setted.");

                    break;
                case InterceptEnumEventType.AfterCall:
                    if (AfterMethod == null)
                        AfterMethod = e.Method;
                    else
                        throw new Exception("type event " + typeEvent.ToString() + " allreader setted.");

                    break;
                case InterceptEnumEventType.Catch:
                    if (CatchMethod == null)
                        CatchMethod = e.Method;
                    else
                        throw new Exception("type event " + typeEvent.ToString() + " allreader setted.");

                    break;
                default:
                    break;
            }

        }

    }



}
